﻿//---------------------------------------------------------------------------
// 
// File: HtmlTokenType.cs
//
// Copyright (C) Microsoft Corporation.  All rights reserved.
//
// Description: Definition of token types supported by HtmlLexicalAnalyzer
//
//---------------------------------------------------------------------------

namespace HTMLConverter.XamlConverters
{
    using System.Xml.Linq;
    using HTMLConverter.Xml;

    /// <summary>
    /// HtmlToXamlConverter is a static class that takes an HTML string
    /// and converts it into XAML
    /// </summary>
    internal class RunConverter : IConverter
    {
        public Tag Type
        {
            get { return Tag.Run; }
        }

        public XmlElement Convert(XNode htmlNode)
        {
            XmlElement run = null;
            if (htmlNode is XmlElement)
            {
                htmlNode = (htmlNode as XmlElement).FirstNode;
            }

            if (htmlNode is XmlText)
            {
                XmlText text = htmlNode as XmlText;
                if (text != null)
                {
                    run = new XmlElement(HtmlConverter.Xaml_Run, HtmlConverter.Xaml_Namespace);
                    run.SetAttribute(HtmlConverter.Xaml_Text, text.Value);
                }
            }

            return run;
        }
    }
}
